package com.mdxl.shiro.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.http.HttpStatus;

@Data
@AllArgsConstructor
public class Result {
    private boolean success;
    private String code;
    private String message;
    private Object data;
    public Result() {
        this.success = true;
        this.code = "200";
    }

    public static Result success(){
        return new Result();
    }

    public static Result success(String msg) {
        Result r = new Result();
        r.setMessage(msg);
        return r;
    }

    public static Result success(String msg, Object object) {
        Result r = new Result();
        r.setMessage(msg);
        r.setData(object);
        return r;
    }

    public static Result success(Object obj) {
        Result r = new Result();
        r.setData(obj);
        return r;
    }
    public static Result error() {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value()+"", "系统发生错误，请重试");
    }

    public static Result error(String msg) {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value()+"", msg);
    }

    public static Result error(String code, String msg) {
        Result r = new Result();
        r.setCode(code);
        r.setMessage(msg);
        return r;
    }
}
